<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>员工档案</span>
      </div>
      <!--搜索-->
      <el-form
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
        style="padding-right: -17px; padding: 0px 20px"
      >
        <el-form-item label="姓名">
          <el-input
            v-model="formInline.name"
            placeholder="请输入姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="性别">
           <el-select
             v-model="formInline.sex"
            placeholder="请输入性别"
          >
            <el-option key="1" value="1" label="男"></el-option>
            <el-option key="2" value="2" label="女"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" required>
          <el-date-picker
            v-model="formInline.birthday"
            type="date"
            placeholder="选择出生日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="primary" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
      <div class="buttonstyle">
        <el-button type="primary" icon="el-icon-plus" @click="onSubmitAdd()"
          >新增</el-button
        >
      </div>
      <!--表格-->
      <el-table :data="tableData">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column
          prop="employeeId"
          label="id"
          width="70"
        ></el-table-column>
        <el-table-column
          prop="doctor.doctorName"
          label="姓名"
          width="90"
        ></el-table-column>
        <el-table-column prop="employeeSex" label="性别" width="90">
          <template slot-scope="scope">{{
            scope.row.employeeSex === 1 ? "男" : "女"
          }}</template>
        </el-table-column>
        <el-table-column
          prop="employeeNationality"
          label="民族"
          width="90"
        ></el-table-column>
        <el-table-column
          prop="employeeEducation"
          label="学历"
          width="110"
        ></el-table-column>
        <el-table-column
          prop="department.departmentName"
          label="职务"
          width="110"
        ></el-table-column>
        <el-table-column
          prop="trialOfSalary"
          label="试用薪资"
          width="110"
        ></el-table-column>
        <el-table-column
          prop="officialSalary"
          label="转正薪资"
          width="110"
        ></el-table-column>
        <el-table-column
          prop="dateOfBirth"
          label="出生日期"
          width="110"
        ></el-table-column>
        <el-table-column
          prop="entryTime"
          label="入职时间"
          width="110"
        ></el-table-column>
        <el-table-column prop="inventory" label="操作" width="180">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="updateemployee(scope.row.employeeId)"
              >修改</el-button
            >
            <el-button
              icon="el-icon-delete"
              size="mini"
              type="danger"
              @click="
                deleteRow(scope.row.employeeId, scope.row.doctor.doctorName)
              "
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="formInline.currentPage"
          :page-sizes="[5, 10, 15]"
          :page-size="formInline.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="formInline.totals"
        >
        </el-pagination>
      </div>
    </el-card>

    <!--弹出增加药品页面框-->
    <el-dialog
      title="员工信息"
      :visible.sync="addKapian"
      width="50%"
      style="text-align: center"
    >
      <el-form
        :inline="true"
        :model="addEmployeeFrom"
        class="demo-form-inline"
        :rules="rules"
        ref="addEmployeeFrom"
      >
        <el-form-item label="员工名称" prop="employeeName">
          <el-input
            v-model="addEmployeeFrom.employeeName"
            placeholder="请输入员工姓名"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="性别"
          prop="employeeSex"
          style="padding-left: 20px"
        >
          <el-select
            v-model="addEmployeeFrom.employeeSex"
            placeholder="请输入员工性别"
          >
            <el-option key="1" value="男"></el-option>
            <el-option key="2" value="女"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="employeeAge">
          <el-input
            v-model="addEmployeeFrom.employeeAge"
            placeholder="请输入员工年龄"
          ></el-input>
        </el-form-item>
        <el-form-item label="民族" prop="employeeNation">
          <el-input
            v-model="addEmployeeFrom.employeeNation"
            placeholder="请输入员工民族"
          ></el-input>
        </el-form-item>
        <el-form-item label="学历" prop="employeeEducation">
          <el-select
            v-model="addEmployeeFrom.employeeEducation"
            placeholder="请输入员工学历"
          >
            <el-option key="1" value="大专"></el-option>
            <el-option key="2" value="研究生"></el-option>
            <el-option key="3" value="博士"></el-option>
            <el-option key="4" value="本科生"></el-option>
            <el-option key="5" value="硕士"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          prop="departmentId"
          label="职务"
          style="padding-left: 20px"
        >
          <el-select
            v-model="addEmployeeFrom.employeeJob"
            placeholder="请选择职务"
          >
            <el-option
              v-for="d in Job"
              :key="d.departmentId"
              :value="d.departmentId"
              :label="d.departmentName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="实习工资" prop="trialOfSalary">
          <el-input
            v-model="addEmployeeFrom.trialOfSalary"
            placeholder="请输入员工实习工资"
          ></el-input>
        </el-form-item>
        <el-form-item label="正式工资" prop="officialSalary">
          <el-input
            v-model="addEmployeeFrom.officialSalary"
            placeholder="请输入员工正式工资"
          ></el-input>
        </el-form-item>
        <el-form-item label="出生日期" prop="dateOfBirth">
          <el-date-picker
            v-model="addEmployeeFrom.dateOfBirth"
            align="left"
            type="date"
            placeholder="请选择出生日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="入职时间" prop="entryTime">
          <el-date-picker
            v-model="addEmployeeFrom.entryTime"
            align="left"
            type="date"
            placeholder="请选择选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <br />
        <el-form-item>
          <el-button type="primary" @click="add()">添加药品</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!--弹出修改页面框-->
    <el-dialog
      title="员工信息"
      :visible.sync="upKapian"
      width="50%"
      style="text-align: center"
    >
      <el-form
        :inline="true"
        class="demo-form-inline"
        :rules="rules"
        ref="upData"
        v-model="upData"
      >
        <el-form-item label="员工名称" prop="doctorName">
          <el-input
            v-model="upData.doctorName"
            placeholder="请输入员工姓名"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="性别"
          prop="employeeSex"
          style="padding-left: 20px"
        >
          <el-select v-model="upData.employeeSex" placeholder="请输入员工性别">
            <el-option :key="1" :value="1" label="男"></el-option>
            <el-option :key="2" :value="2" label="女"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="employeeAge">
          <el-input
            v-model="upData.employeeAge"
            placeholder="请输入员工年龄"
          ></el-input>
        </el-form-item>
        <el-form-item label="民族" prop="employeeNation">
          <el-input
            v-model="upData.employeeNationality"
            placeholder="请输入员工民族"
          ></el-input>
        </el-form-item>
        <el-form-item label="学历" prop="employeeEducation">
          <el-select
            v-model="upData.employeeEducation"
            placeholder="请输入员工学历"
          >
            <el-option key="1" value="大专"></el-option>
            <el-option key="2" value="研究生"></el-option>
            <el-option key="3" value="博士"></el-option>
            <el-option key="4" value="本科生"></el-option>
            <el-option key="5" value="硕士"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          prop="departmentId"
          label="职务"
          style="padding-left: 20px"
        >
          <el-select v-model="upData.departmentId"  placeholder="请选择职务">
            <el-option
              v-for="d in Job"
              :key="d.departmentId"
              :value="d.departmentId"
              :label="d.departmentName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="实习工资" prop="trialOfSalary">
          <el-input
            v-model="upData.trialOfSalary"
            placeholder="请输入员工实习工资"
          ></el-input>
        </el-form-item>
        <el-form-item label="正式工资" prop="officialSalary">
          <el-input
            v-model="upData.officialSalary"
            placeholder="请输入员工正式工资"
          ></el-input>
        </el-form-item>
        <el-form-item label="出生日期" prop="dateOfBirth">
          <el-date-picker
            v-model="upData.dateOfBirth"
            align="left"
            type="date"
            placeholder="请选择出生日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="入职时间" prop="entryTime">
          <el-date-picker
            v-model="upData.entryTime"
            align="left"
            type="date"
            placeholder="请选择选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <br />
        <el-form-item>
          <el-button type="primary" @click="change()">修改员工</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formInline: {
        name: "",
        sex: "",
        birthday: "",
        currentPage: 1,
        pageSize: 5,
        totals: 10,
      },
      tableData: [],
      Job: {
        employeeId: "",
        doctorId: "",
      },
      upData: {},
      addEmployeeFrom: {
        doctorName: "",
        employeeSex: "",
        employeeAge: "",
        employeeNation: "",
        employeeEducation: "",
        employeeJob: "",
        trialOfSalary: "",
        officialSalary: "",
        dateOfBirth: "",
        entryTime: "",
      },
      upKapian: false,
      addKapian: false,
      rules: {
       
      },
    };
  },
  methods: {
    //查询
    onSubmit() {
      this.$axios
        .post("/api/biz/document/list", this.formInline)
        .then((res) => {
          console.log(res);
          if (res.data != null) {
            this.tableData = res.data.data.data;
            this.formInline.totals = res.data.data.totals;
          }
        });
    },
    //重置
    reset() {
      (this.formInline.name = ""),
        (this.formInline.sex = ""),
        (this.formInline.birthday = "");
    },
    //添加
    onSubmitAdd() {
      this.addKapian = true;
    },

    add() {
      //添加数据
      this.$axios
        .post("/api/biz/document/add", this.addEmployeeFrom)
        .then((res) => {
          this.addKapian = false;
          this.rules = null;
          this.onSubmit();
        });
    },
    //设置每页多少条
    handleSizeChange(pageSize) {
      this.formInline.pageSize = pageSize;
      this.onSubmit();
    },
    //下一页
    handleCurrentChange(currentPage) {
      this.formInline.currentPage = currentPage;
      this.onSubmit();
    },
    //删除员工
    deleteRow(id, name) {
      this.$confirm("此操作将永久删除" + name + ", 是否继续?", "提示", {}).then(
        () => {
          this.$axios.post("/api/biz/document/del/" + id).then((res) => {
            let data = res.data;
            if (data !== null) {
              this.$message.success(data.msg);
            } else {
              this.$message.success(data.msg);
            }
            
          });
        }
      );
    },
    //根据id查询员工
    updateemployee(id) {
      this.upKapian = true;
      this.$axios.post("/api/biz/document/update/" + id).then((res) => {
        this.upData = res.data.data;
      });
    },
    //修改员工
    change() {
      this.$axios
        .post("/api/biz/document/updateEmployee", this.upData)
        .then((res) => {
          if (res.data.msg == "修改成功") {
            this.upKapian = false;
            this.onSubmit();
          }
        });
    },
  },
  mounted() {
    //默认加载list页面
    this.$axios.post("/api/biz/document/list", this.formInline).then((res) => {
      console.log(res);
      if (res.data != null) {
        this.tableData = res.data.data.data;
        this.formInline.totals = res.data.data.totals;
      }
    });
    //加载下拉列表
    this.$axios.post("/api/biz/document/Spinner").then((res) => {
      this.Job = res.data.data;
    });
  },
};
</script>

<style scope>
.el-pagination {
  float: right;
  margin: 30px 0px;
}
.el-table th.el-table__cell > .cell {
  text-align: center;
}
.el-table--enable-row-transition .el-table__body td.el-table__cell {
  text-align: center;
}
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}
.buttonstyle{
    margin-right: 100%;
    
}
.box-card {
  width: auto;
  margin-top: 0;
}
.buttonstyle {
  margin-right: 70%;
}
</style>